package com.youbug.kefu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.kefu.entity.DicType;
import com.youbug.kefu.entity.Dictionary;
import com.youbug.kefu.service.IDicTypeService;
import com.youbug.kefu.service.IDictionaryService;
import com.youbug.kefu.vo.PageQueryVo;
import com.youbug.kefu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-02-12
 */
@RestController
@RequestMapping("/useDic")
public class UseDicController {

    @Autowired
    private IDicTypeService dicTypeService;

    @Autowired
    private IDictionaryService dictionaryService;

    @GetMapping("/getDicItems/{typeCode}")
    public R<List<Dictionary>> getDicTypes(@PathVariable String typeCode){

        QueryWrapper<Dictionary> dictionaryWrapper = new QueryWrapper<>();

        dictionaryWrapper.eq("type_code", typeCode);

        dictionaryWrapper.orderByAsc("order_id");

        List<Dictionary> list = dictionaryService.list(dictionaryWrapper);

        return R.ok(list);
    }

    
    @GetMapping("/dicCodeTrans/{typeCode}/{itemCode}")
    public R<String> dicCodeTrans(@PathVariable String typeCode,@PathVariable String itemCode){

        QueryWrapper<Dictionary> dictionaryWrapper = new QueryWrapper<>();

        dictionaryWrapper.eq("type_code", typeCode);

        dictionaryWrapper.eq("code", itemCode);

        Dictionary dictionary = dictionaryService.getOne(dictionaryWrapper);

        return R.ok(dictionary == null ? "-" : dictionary.getValue());
    }
}

